package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.DailyTrainInfoQueryDto;
import com.leo.train.business.entity.DailyTrainInfo;
import com.leo.train.business.service.DailyTrainInfoService;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/daily-trainInfo")
public class DailyTrainInfoAdminController {
    @Autowired
    private DailyTrainInfoService dailyTrainInfoService;
    /**
     * 新增
     * @param dailyTrainInfo
     * @return
     */
    @PostMapping("add")
    public CommonResp save(@RequestBody DailyTrainInfo dailyTrainInfo) {
        dailyTrainInfoService.save(dailyTrainInfo);
        return new CommonResp<>();
    }

    /**
     * 修改
     * @param dailyTrainInfo
     * @return
     */
    @PostMapping("/update")
    public CommonResp update(@RequestBody DailyTrainInfo dailyTrainInfo) {
        dailyTrainInfoService.save(dailyTrainInfo);
        return new CommonResp<>();
    }

    /**
     * 删除
     * @param map
     * @return
     */
    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Map<String,Long> map){
        dailyTrainInfoService.delete(map.get("id"));
        return new CommonResp<>();
    }

    /**
     * 查询火车列表
     * @return
     */
    @GetMapping("/list")
    public CommonResp<PageResult<DailyTrainInfo>> list(DailyTrainInfoQueryDto dailyTrainInfoQueryDto) {
        PageResult<DailyTrainInfo> pageResult = dailyTrainInfoService.list(dailyTrainInfoQueryDto);
        return new CommonResp<>(pageResult);
    }

    /**
     * 查询火车详情信息
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public  CommonResp<DailyTrainInfo> detail(@RequestParam Long id) {
        DailyTrainInfo dailyTrainInfo = dailyTrainInfoService.detail(id);
        return new CommonResp<>(dailyTrainInfo);
    }

}
